var e = require("../../../@babel/runtime/helpers/createForOfIteratorHelper"), r = require("../../../@babel/runtime/helpers/defineProperty"), t = require("../../../@babel/runtime/helpers/classCallCheck"), n = require("../../../@babel/runtime/helpers/createClass"), a = require("../../../common/vendor.js"), o = function() {
    function o() {
        t(this, o);
    }
    return n(o, null, [ {
        key: "hasKey",
        value: function(e) {
            return o.getAllKeys().includes(e);
        }
    }, {
        key: "addKey",
        value: function(e) {
            var t = a.index.getStorageSync("storage_key_map");
            t ? (t[e] = !0, a.index.setStorageSync("storage_key_map", t)) : a.index.setStorageSync("storage_key_map", r({}, e, !0));
        }
    }, {
        key: "removeKey",
        value: function(e) {
            var r = a.index.getStorageSync("storage_key_map");
            r && (delete r[e], a.index.setStorageSync("storage_key_map", r));
        }
    }, {
        key: "getAllKeys",
        value: function() {
            var e = a.index.getStorageSync("storage_key_map");
            return e ? Object.keys(e) : [];
        }
    }, {
        key: "set",
        value: function(e, r) {
            var t = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : null, n = null;
            "number" == typeof t && (n = Date.now() + t);
            try {
                a.index.setStorageSync(e, {
                    data: r,
                    expires: n
                }), o.addKey(e);
            } catch (e) {
                e = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(e);
                console.error(e);
            }
        }
    }, {
        key: "get",
        value: function(e) {
            var r = a.index.getStorageSync(e);
            if (!r) return null;
            var t = r.data, n = r.expires;
            return n ? n - Date.now() > 0 ? t : (o.remove(e), o.removeKey(e), null) : t;
        }
    }, {
        key: "remove",
        value: function(e) {
            a.index.removeStorageSync(e), o.removeKey(e);
        }
    }, {
        key: "removeAll",
        value: function() {
            var r, t = o.getAllKeys(), n = e(t);
            try {
                for (n.s(); !(r = n.n()).done; ) {
                    var l = r.value;
                    a.index.removeStorageSync(l), o.removeKey(l);
                }
            } catch (e) {
                e = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(e);
                n.e(e);
            } finally {
                n.f();
            }
        }
    } ]), o;
}();

exports.Storage = o;